package com.cloudbroker.bcs.platform.ltb.middle.service.impl;

import com.alibaba.fastjson.JSON;
import com.cloudbroker.bcs.platform.ltb.bizapi.service.admin.vo.BlackKeyWordForm;
import com.cloudbroker.bcs.platform.ltb.middle.entity.BlackWord;
import com.cloudbroker.bcs.platform.ltb.middle.service.BlackWordService;
import com.cloudbroker.bcs.platform.ltb.middle.util.StringReplacer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by lili19289 on 2016/7/21.
 */
public class InitBlackWord  implements ApplicationListener<ContextRefreshedEvent> {
    private static final Logger LOGGER = LoggerFactory.getLogger(InitBlackWord.class);
    @Resource
    private BlackWordService blackWordService;

    @Override
    public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
        if(contextRefreshedEvent.getApplicationContext().getParent() == null){//root application context 没有parent，他就是老大.
            //需要执行的逻辑代码，当spring容器初始化完成后就会执行该方法。
            List<BlackWord> words = blackWordService.fetchAllBlackWords(new BlackKeyWordForm());
            StringReplacer.init(words);
        }
    }


}
